from selenium.webdriver.common.by import By

from base.base_page import BasePage

# 对象库层
class IndexPage(BasePage):

    def find_login_btn(self):
        login_btn_element = self.get_element(By.CSS_SELECTOR,'.red')  # 调用的是自己定义的元素查找方法，因为在类的内部调用，所以直接就是self
        return login_btn_element


    def find_register_btn(self):
        reg_btn_element = self.get_element(By.XPATH,'//div[@class="fl nologin"]/a[2]')
        return reg_btn_element



# 操作层
class IndexHandler:
    def __init__(self):
        self.index_page_obj = IndexPage()

    # 点击登录按钮
    def click_login_element(self):
        # 找到登录按钮
        self.index_page_obj.find_login_btn().click()




    # 点击注册按钮
    def click_reg_element(self):
        # 找到注册按钮,点击登录
        self.index_page_obj.find_register_btn().click()




# 业务层
class IndexAct:
    def __init__(self):
        self.index_handler_obj = IndexHandler()

    # 跳转到登录页面
    def link_to_login_page(self):
        self.index_handler_obj.click_login_element()


    # 跳转到注册页面
    def link_to_register_page(self):
        self.index_handler_obj.click_reg_element()
